package com.lecyon.farm.vo.query;

import com.lecyon.farm.common.constant.CommonConstant;
import com.lecyon.farm.util.StringHelper;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @author Yao Zheng
 * @Date 2020/4/20 14:46
 */
@Data
@ApiModel("查询GPS图片信息Vo For elasticsearch")
public class QueryGpsPictureInformationVo {

    private String indexName = "gps_pic_info";

    private String id;

    private String carId;

    private String beginTime;

    private String endTime;

    public String getBeginTime() {
        if (StringHelper.isEmpty(beginTime)) {
            LocalDateTime begin = LocalDateTime.of(LocalDate.now().plusDays(-1), LocalTime.MIN);
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(CommonConstant.DATE_TIME_FORMAT_PATTERN);
            beginTime = dateTimeFormatter.format(begin);
        }
        return beginTime;
    }

    public String getEndTime() {
        // 结束时间设置为当前时间
        if (StringHelper.isEmpty(endTime)) {
            LocalDateTime end = LocalDateTime.of(LocalDate.now().plusDays(-1), LocalTime.MAX);
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(CommonConstant.DATE_TIME_FORMAT_PATTERN);
            endTime = dateTimeFormatter.format(end);
        }
        return endTime;
    }

}
